# from _hellchin_webrun.src.core.browser.base import BaseBrowser
from typing import Literal

# from _hellchin_webrun.src.core.utils.logger.run_logger import TestLogger
from _hellchin_webrun.src.core.utils.chinese_alias import KeyWordManage
from _hellchin_webrun.src.core.browser.base import BaseTest


class FrameInteractions(BaseTest):  # BaseBrowser
    """iframe相关的操作"""

    @KeyWordManage.chinese_alias("iframe内元素输入", "在iframe中填充输入框")
    def frame_fill_value(self, frame, locator, value, timeout=3000):
        """在iframe中填充输入框"""
        # print(f"正在iframe中元素:{locator}，输入值:{value}")
        # TestLogger.start.suit_log(f"正在iframe中元素:{locator}，输入值:{value}")
        self.page.frame_locator(frame).locator(locator).fill(value, timeout=timeout)
        # TestLogger.success.suit_log(f"成功输入值:{value}")

    @KeyWordManage.chinese_alias("iframe内元素点击", "在iframe中点击元素")
    def frame_click_element(
            self,
            frame,
            locator,
            *,
            button: Literal["left", "middle", "right"] | None = 'left',
            count: int = 1,
            timeout: int = 3000
    ) -> None:
        """点击iframe中的元素"""
        # print(f"正在点击iframe中元素:{locator}")
        # TestLogger.start.suit_log(f"正在点击iframe中元素:{locator}")
        self.page.frame_locator(frame).locator(locator).click(
            button=button, click_count=count, timeout=timeout
        )
        # TestLogger.success.suit_log("成功点击元素")

    @KeyWordManage.chinese_alias("iframe内下拉选择框选择", "iframe内下拉框选择")
    def frame_select_option(self, frame, locator, value, *, timeout: float=3000):
        """在iframe中选择下拉框选项"""
        # print(f"正在选择iframe中下拉框:{locator}，选项的值:{value}")
        # TestLogger.start.suit_log(f"正在选择iframe中下拉框:{locator}，选项的值:{value}")
        self.page.frame_locator(frame).locator(locator).select_option(value, timeout=timeout)
        # TestLogger.success.suit_log("成功选择下拉框选项")

    @KeyWordManage.chinese_alias("iframe内拖拽元素", "iframe内元素拖拽")
    def frame_drag_and_drop(
            self,
            frame,
            start_selector,
            end_selector,
            *,
            timeout: float = 3000
    ) -> None:
        """在iframe中拖拽元素"""
        # print(f"正在iframe中拖拽元素:{start_selector}，拖拽到的元素:{end_selector}")
        # TestLogger.start.suit_log(f"正在iframe中拖拽元素:{start_selector}，拖拽到的元素:{end_selector}")
        s_ele = self.page.frame_locator(frame).locator(start_selector)
        e_ele = self.page.frame_locator(frame).locator(end_selector)
        s_ele.drag_to(e_ele, timeout=timeout)
        # TestLogger.success.suit_log("成功拖拽元素")
